/*      */ package com.iris.egrant.utils;
/*      */ 
/*      */ import java.util.ArrayList;
/*      */ import java.util.List;
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ public class Encrypt
/*      */ {
/*      */   public static final String firstKey = "pdcss";
/*      */   public static final String secondKey = "css";
/*      */   public static final String thirdKey = "co";
/*      */   
/*      */   public static String strDecode(String source) {
/*   26 */     return strDecode(source, "pdcss", "css", "co");
/*      */   }
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   
/*      */   public static String strEncode(String data, String firstKey, String secondKey, String thirdKey) {
/*   34 */     int leng = data.length();
/*   35 */     String encData = "";
/*   36 */     List<int[]> firstKeyBt = null, secondKeyBt = null, thirdKeyBt = null;
/*   37 */     int firstLength = 0, secondLength = 0, thirdLength = 0;
/*   38 */     if (firstKey != null && firstKey != "") {
/*   39 */       firstKeyBt = getKeyBytes(firstKey);
/*   40 */       firstLength = firstKeyBt.size();
/*      */     } 
/*   42 */     if (secondKey != null && secondKey != "") {
/*   43 */       secondKeyBt = getKeyBytes(secondKey);
/*   44 */       secondLength = secondKeyBt.size();
/*      */     } 
/*   46 */     if (thirdKey != null && thirdKey != "") {
/*   47 */       thirdKeyBt = getKeyBytes(thirdKey);
/*   48 */       thirdLength = thirdKeyBt.size();
/*      */     } 
/*      */     
/*   51 */     if (leng > 0) {
/*   52 */       if (leng < 4) {
/*   53 */         int[] bt = strToBt(data);
/*   54 */         int[] encByte = null;
/*   55 */         if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != "") {
/*      */ 
/*      */           
/*   58 */           int x = 0, y = 0, z = 0;
/*   59 */           int[] tempBt = bt;
/*   60 */           for (x = 0; x < firstLength; x++) {
/*   61 */             tempBt = enc(tempBt, firstKeyBt.get(x));
/*      */           }
/*   63 */           for (y = 0; y < secondLength; y++) {
/*   64 */             tempBt = enc(tempBt, secondKeyBt.get(y));
/*      */           }
/*   66 */           for (z = 0; z < thirdLength; z++) {
/*   67 */             tempBt = enc(tempBt, thirdKeyBt.get(z));
/*      */           }
/*   69 */           encByte = tempBt;
/*      */         }
/*   71 */         else if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "") {
/*      */           
/*   73 */           int x = 0, y = 0;
/*   74 */           int[] tempBt = bt;
/*   75 */           for (x = 0; x < firstLength; x++) {
/*   76 */             tempBt = enc(tempBt, firstKeyBt.get(x));
/*      */           }
/*   78 */           for (y = 0; y < secondLength; y++) {
/*   79 */             tempBt = enc(tempBt, secondKeyBt.get(y));
/*      */           }
/*   81 */           encByte = tempBt;
/*      */         }
/*   83 */         else if (firstKey != null && firstKey != "") {
/*      */           
/*   85 */           int x = 0;
/*   86 */           int[] tempBt = bt;
/*   87 */           for (x = 0; x < firstLength; x++) {
/*   88 */             tempBt = enc(tempBt, firstKeyBt.get(x));
/*      */           }
/*   90 */           encByte = tempBt;
/*      */         } 
/*      */ 
/*      */         
/*   94 */         encData = bt64ToHex(encByte);
/*      */       } else {
/*   96 */         int iterator = leng / 4;
/*   97 */         int remainder = leng % 4;
/*   98 */         int i = 0;
/*   99 */         for (i = 0; i < iterator; i++) {
/*  100 */           String tempData = data.substring(i * 4 + 0, i * 4 + 4);
/*  101 */           int[] tempByte = strToBt(tempData);
/*  102 */           int[] encByte = null;
/*  103 */           if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != "") {
/*      */ 
/*      */             
/*  106 */             int x = 0, y = 0, z = 0;
/*  107 */             int[] tempBt = tempByte;
/*  108 */             for (x = 0; x < firstLength; x++) {
/*  109 */               tempBt = enc(tempBt, firstKeyBt.get(x));
/*      */             }
/*  111 */             for (y = 0; y < secondLength; y++) {
/*  112 */               tempBt = enc(tempBt, secondKeyBt.get(y));
/*      */             }
/*  114 */             for (z = 0; z < thirdLength; z++) {
/*  115 */               tempBt = enc(tempBt, thirdKeyBt.get(z));
/*      */             }
/*  117 */             encByte = tempBt;
/*      */           }
/*  119 */           else if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "") {
/*      */             
/*  121 */             int x = 0, y = 0;
/*  122 */             int[] tempBt = tempByte;
/*  123 */             for (x = 0; x < firstLength; x++) {
/*  124 */               tempBt = enc(tempBt, firstKeyBt.get(x));
/*      */             }
/*  126 */             for (y = 0; y < secondLength; y++) {
/*  127 */               tempBt = enc(tempBt, secondKeyBt.get(y));
/*      */             }
/*  129 */             encByte = tempBt;
/*      */           }
/*  131 */           else if (firstKey != null && firstKey != "") {
/*      */             
/*  133 */             int x = 0;
/*  134 */             int[] tempBt = tempByte;
/*  135 */             for (x = 0; x < firstLength; x++) {
/*  136 */               tempBt = enc(tempBt, firstKeyBt.get(x));
/*      */             }
/*  138 */             encByte = tempBt;
/*      */           } 
/*      */ 
/*      */           
/*  142 */           encData = encData + bt64ToHex(encByte);
/*      */         } 
/*  144 */         if (remainder > 0) {
/*  145 */           String remainderData = data.substring(iterator * 4 + 0, leng);
/*  146 */           int[] tempByte = strToBt(remainderData);
/*  147 */           int[] encByte = null;
/*  148 */           if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != "") {
/*      */ 
/*      */             
/*  151 */             int x = 0, y = 0, z = 0;
/*  152 */             int[] tempBt = tempByte;
/*  153 */             for (x = 0; x < firstLength; x++) {
/*  154 */               tempBt = enc(tempBt, firstKeyBt.get(x));
/*      */             }
/*  156 */             for (y = 0; y < secondLength; y++) {
/*  157 */               tempBt = enc(tempBt, secondKeyBt.get(y));
/*      */             }
/*  159 */             for (z = 0; z < thirdLength; z++) {
/*  160 */               tempBt = enc(tempBt, thirdKeyBt.get(z));
/*      */             }
/*  162 */             encByte = tempBt;
/*      */           }
/*  164 */           else if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "") {
/*      */             
/*  166 */             int x = 0, y = 0;
/*  167 */             int[] tempBt = tempByte;
/*  168 */             for (x = 0; x < firstLength; x++) {
/*  169 */               tempBt = enc(tempBt, firstKeyBt.get(x));
/*      */             }
/*  171 */             for (y = 0; y < secondLength; y++) {
/*  172 */               tempBt = enc(tempBt, secondKeyBt.get(y));
/*      */             }
/*  174 */             encByte = tempBt;
/*      */           }
/*  176 */           else if (firstKey != null && firstKey != "") {
/*      */             
/*  178 */             int x = 0;
/*  179 */             int[] tempBt = tempByte;
/*  180 */             for (x = 0; x < firstLength; x++) {
/*  181 */               tempBt = enc(tempBt, firstKeyBt.get(x));
/*      */             }
/*  183 */             encByte = tempBt;
/*      */           } 
/*      */ 
/*      */           
/*  187 */           encData = encData + bt64ToHex(encByte);
/*      */         } 
/*      */       } 
/*      */     }
/*  191 */     return encData;
/*      */   }
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   
/*      */   public static String strDecode(String data, String firstKey, String secondKey, String thirdKey) {
/*  200 */     int leng = data.length();
/*  201 */     String decStr = "";
/*  202 */     List<int[]> firstKeyBt = null, secondKeyBt = null, thirdKeyBt = null;
/*  203 */     int firstLength = 0, secondLength = 0, thirdLength = 0;
/*  204 */     if (firstKey != null && firstKey != "") {
/*  205 */       firstKeyBt = getKeyBytes(firstKey);
/*  206 */       firstLength = firstKeyBt.size();
/*      */     } 
/*  208 */     if (secondKey != null && secondKey != "") {
/*  209 */       secondKeyBt = getKeyBytes(secondKey);
/*  210 */       secondLength = secondKeyBt.size();
/*      */     } 
/*  212 */     if (thirdKey != null && thirdKey != "") {
/*  213 */       thirdKeyBt = getKeyBytes(thirdKey);
/*  214 */       thirdLength = thirdKeyBt.size();
/*      */     } 
/*      */     
/*  217 */     int iterator = leng / 16;
/*  218 */     int i = 0;
/*  219 */     for (i = 0; i < iterator; i++) {
/*  220 */       String tempData = data.substring(i * 16 + 0, i * 16 + 16);
/*  221 */       String strByte = hexToBt64(tempData);
/*  222 */       int[] intByte = new int[64];
/*  223 */       int j = 0;
/*  224 */       for (j = 0; j < 64; j++) {
/*  225 */         intByte[j] = Integer.parseInt(strByte.substring(j, j + 1), 10);
/*      */       }
/*  227 */       int[] decByte = null;
/*  228 */       if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != "") {
/*      */ 
/*      */         
/*  231 */         int x = 0, y = 0, z = 0;
/*  232 */         int[] tempBt = intByte;
/*  233 */         for (x = thirdLength - 1; x >= 0; x--) {
/*  234 */           tempBt = dec(tempBt, thirdKeyBt.get(x));
/*      */         }
/*  236 */         for (y = secondLength - 1; y >= 0; y--) {
/*  237 */           tempBt = dec(tempBt, secondKeyBt.get(y));
/*      */         }
/*  239 */         for (z = firstLength - 1; z >= 0; z--) {
/*  240 */           tempBt = dec(tempBt, firstKeyBt.get(z));
/*      */         }
/*  242 */         decByte = tempBt;
/*      */       }
/*  244 */       else if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "") {
/*      */         
/*  246 */         int x = 0, y = 0;
/*  247 */         int[] tempBt = intByte;
/*  248 */         for (x = secondLength - 1; x >= 0; x--) {
/*  249 */           tempBt = dec(tempBt, secondKeyBt.get(x));
/*      */         }
/*  251 */         for (y = firstLength - 1; y >= 0; y--) {
/*  252 */           tempBt = dec(tempBt, firstKeyBt.get(y));
/*      */         }
/*  254 */         decByte = tempBt;
/*      */       }
/*  256 */       else if (firstKey != null && firstKey != "") {
/*      */         
/*  258 */         int x = 0;
/*  259 */         int[] tempBt = intByte;
/*  260 */         for (x = firstLength - 1; x >= 0; x--) {
/*  261 */           tempBt = dec(tempBt, firstKeyBt.get(x));
/*      */         }
/*  263 */         decByte = tempBt;
/*      */       } 
/*      */ 
/*      */       
/*  267 */       decStr = decStr + byteToString(decByte);
/*      */     } 
/*  269 */     return decStr;
/*      */   }
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   
/*      */   public static List getKeyBytes(String key) {
/*  278 */     List<int[]> keyBytes = new ArrayList();
/*  279 */     int leng = key.length();
/*  280 */     int iterator = leng / 4;
/*  281 */     int remainder = leng % 4;
/*  282 */     int i = 0;
/*  283 */     for (i = 0; i < iterator; i++) {
/*  284 */       keyBytes.add(i, strToBt(key.substring(i * 4 + 0, i * 4 + 4)));
/*      */     }
/*  286 */     if (remainder > 0) {
/*  287 */       keyBytes.add(i, strToBt(key.substring(i * 4 + 0, leng)));
/*      */     }
/*  289 */     return keyBytes;
/*      */   }
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   
/*      */   public static int[] strToBt(String str) {
/*  298 */     int leng = str.length();
/*  299 */     int[] bt = new int[64];
/*  300 */     if (leng < 4) {
/*  301 */       int i = 0, j = 0, p = 0, q = 0;
/*  302 */       for (i = 0; i < leng; i++) {
/*  303 */         int k = str.charAt(i);
/*  304 */         for (j = 0; j < 16; j++) {
/*  305 */           int pow = 1, m = 0;
/*  306 */           for (m = 15; m > j; m--) {
/*  307 */             pow *= 2;
/*      */           }
/*  309 */           bt[16 * i + j] = k / pow % 2;
/*      */         } 
/*      */       } 
/*  312 */       for (p = leng; p < 4; p++) {
/*  313 */         int k = 0;
/*  314 */         for (q = 0; q < 16; q++) {
/*  315 */           int pow = 1, m = 0;
/*  316 */           for (m = 15; m > q; m--) {
/*  317 */             pow *= 2;
/*      */           }
/*  319 */           bt[16 * p + q] = k / pow % 2;
/*      */         } 
/*      */       } 
/*      */     } else {
/*  323 */       for (int i = 0; i < 4; i++) {
/*  324 */         int k = str.charAt(i);
/*  325 */         for (int j = 0; j < 16; j++) {
/*  326 */           int pow = 1;
/*  327 */           for (int m = 15; m > j; m--) {
/*  328 */             pow *= 2;
/*      */           }
/*  330 */           bt[16 * i + j] = k / pow % 2;
/*      */         } 
/*      */       } 
/*      */     } 
/*  334 */     return bt;
/*      */   }
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   
/*      */   public static String bt4ToHex(String binary) {
/*  343 */     String hex = "";
/*  344 */     if (binary.equalsIgnoreCase("0000")) {
/*  345 */       hex = "0";
/*  346 */     } else if (binary.equalsIgnoreCase("0001")) {
/*  347 */       hex = "1";
/*  348 */     } else if (binary.equalsIgnoreCase("0010")) {
/*  349 */       hex = "2";
/*  350 */     } else if (binary.equalsIgnoreCase("0011")) {
/*  351 */       hex = "3";
/*  352 */     } else if (binary.equalsIgnoreCase("0100")) {
/*  353 */       hex = "4";
/*  354 */     } else if (binary.equalsIgnoreCase("0101")) {
/*  355 */       hex = "5";
/*  356 */     } else if (binary.equalsIgnoreCase("0110")) {
/*  357 */       hex = "6";
/*  358 */     } else if (binary.equalsIgnoreCase("0111")) {
/*  359 */       hex = "7";
/*  360 */     } else if (binary.equalsIgnoreCase("1000")) {
/*  361 */       hex = "8";
/*  362 */     } else if (binary.equalsIgnoreCase("1001")) {
/*  363 */       hex = "9";
/*  364 */     } else if (binary.equalsIgnoreCase("1010")) {
/*  365 */       hex = "A";
/*  366 */     } else if (binary.equalsIgnoreCase("1011")) {
/*  367 */       hex = "B";
/*  368 */     } else if (binary.equalsIgnoreCase("1100")) {
/*  369 */       hex = "C";
/*  370 */     } else if (binary.equalsIgnoreCase("1101")) {
/*  371 */       hex = "D";
/*  372 */     } else if (binary.equalsIgnoreCase("1110")) {
/*  373 */       hex = "E";
/*  374 */     } else if (binary.equalsIgnoreCase("1111")) {
/*  375 */       hex = "F";
/*      */     } 
/*  377 */     return hex;
/*      */   }
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   
/*      */   public static String hexToBt4(String hex) {
/*  386 */     String binary = "";
/*  387 */     if (hex.equalsIgnoreCase("0")) {
/*  388 */       binary = "0000";
/*  389 */     } else if (hex.equalsIgnoreCase("1")) {
/*  390 */       binary = "0001";
/*      */     } 
/*  392 */     if (hex.equalsIgnoreCase("2")) {
/*  393 */       binary = "0010";
/*      */     }
/*  395 */     if (hex.equalsIgnoreCase("3")) {
/*  396 */       binary = "0011";
/*      */     }
/*  398 */     if (hex.equalsIgnoreCase("4")) {
/*  399 */       binary = "0100";
/*      */     }
/*  401 */     if (hex.equalsIgnoreCase("5")) {
/*  402 */       binary = "0101";
/*      */     }
/*  404 */     if (hex.equalsIgnoreCase("6")) {
/*  405 */       binary = "0110";
/*      */     }
/*  407 */     if (hex.equalsIgnoreCase("7")) {
/*  408 */       binary = "0111";
/*      */     }
/*  410 */     if (hex.equalsIgnoreCase("8")) {
/*  411 */       binary = "1000";
/*      */     }
/*  413 */     if (hex.equalsIgnoreCase("9")) {
/*  414 */       binary = "1001";
/*      */     }
/*  416 */     if (hex.equalsIgnoreCase("A")) {
/*  417 */       binary = "1010";
/*      */     }
/*  419 */     if (hex.equalsIgnoreCase("B")) {
/*  420 */       binary = "1011";
/*      */     }
/*  422 */     if (hex.equalsIgnoreCase("C")) {
/*  423 */       binary = "1100";
/*      */     }
/*  425 */     if (hex.equalsIgnoreCase("D")) {
/*  426 */       binary = "1101";
/*      */     }
/*  428 */     if (hex.equalsIgnoreCase("E")) {
/*  429 */       binary = "1110";
/*      */     }
/*  431 */     if (hex.equalsIgnoreCase("F")) {
/*  432 */       binary = "1111";
/*      */     }
/*  434 */     return binary;
/*      */   }
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   
/*      */   public static String byteToString(int[] byteData) {
/*  443 */     String str = "";
/*  444 */     for (int i = 0; i < 4; i++) {
/*  445 */       int count = 0;
/*  446 */       for (int j = 0; j < 16; j++) {
/*  447 */         int pow = 1;
/*  448 */         for (int m = 15; m > j; m--) {
/*  449 */           pow *= 2;
/*      */         }
/*  451 */         count += byteData[16 * i + j] * pow;
/*      */       } 
/*  453 */       if (count != 0) {
/*  454 */         str = str + "" + (char)count;
/*      */       }
/*      */     } 
/*  457 */     return str;
/*      */   }
/*      */   
/*      */   public static String bt64ToHex(int[] byteData) {
/*  461 */     String hex = "";
/*  462 */     for (int i = 0; i < 16; i++) {
/*  463 */       String bt = "";
/*  464 */       for (int j = 0; j < 4; j++) {
/*  465 */         bt = bt + byteData[i * 4 + j];
/*      */       }
/*  467 */       hex = hex + bt4ToHex(bt);
/*      */     } 
/*  469 */     return hex;
/*      */   }
/*      */   
/*      */   public static String hexToBt64(String hex) {
/*  473 */     String binary = "";
/*  474 */     for (int i = 0; i < 16; i++) {
/*  475 */       binary = binary + hexToBt4(hex.substring(i, i + 1));
/*      */     }
/*  477 */     return binary;
/*      */   }
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   
/*      */   public static int[] enc(int[] dataByte, int[] keyByte) {
/*  485 */     int[][] keys = generateKeys(keyByte);
/*  486 */     int[] ipByte = initPermute(dataByte);
/*  487 */     int[] ipLeft = new int[32];
/*  488 */     int[] ipRight = new int[32];
/*  489 */     int[] tempLeft = new int[32];
/*  490 */     int i = 0, j = 0, k = 0, m = 0, n = 0;
/*  491 */     for (k = 0; k < 32; k++) {
/*  492 */       ipLeft[k] = ipByte[k];
/*  493 */       ipRight[k] = ipByte[32 + k];
/*      */     } 
/*  495 */     for (i = 0; i < 16; i++) {
/*  496 */       for (j = 0; j < 32; j++) {
/*  497 */         tempLeft[j] = ipLeft[j];
/*  498 */         ipLeft[j] = ipRight[j];
/*      */       } 
/*  500 */       int[] key = new int[48];
/*  501 */       for (m = 0; m < 48; m++) {
/*  502 */         key[m] = keys[i][m];
/*      */       }
/*  504 */       int[] tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight), key))), tempLeft);
/*  505 */       for (n = 0; n < 32; n++) {
/*  506 */         ipRight[n] = tempRight[n];
/*      */       }
/*      */     } 
/*      */ 
/*      */     
/*  511 */     int[] finalData = new int[64];
/*  512 */     for (i = 0; i < 32; i++) {
/*  513 */       finalData[i] = ipRight[i];
/*  514 */       finalData[32 + i] = ipLeft[i];
/*      */     } 
/*  516 */     return finallyPermute(finalData);
/*      */   }
/*      */   
/*      */   public static int[] dec(int[] dataByte, int[] keyByte) {
/*  520 */     int[][] keys = generateKeys(keyByte);
/*  521 */     int[] ipByte = initPermute(dataByte);
/*  522 */     int[] ipLeft = new int[32];
/*  523 */     int[] ipRight = new int[32];
/*  524 */     int[] tempLeft = new int[32];
/*  525 */     int i = 0, j = 0, k = 0, m = 0, n = 0;
/*  526 */     for (k = 0; k < 32; k++) {
/*  527 */       ipLeft[k] = ipByte[k];
/*  528 */       ipRight[k] = ipByte[32 + k];
/*      */     } 
/*  530 */     for (i = 15; i >= 0; i--) {
/*  531 */       for (j = 0; j < 32; j++) {
/*  532 */         tempLeft[j] = ipLeft[j];
/*  533 */         ipLeft[j] = ipRight[j];
/*      */       } 
/*  535 */       int[] key = new int[48];
/*  536 */       for (m = 0; m < 48; m++) {
/*  537 */         key[m] = keys[i][m];
/*      */       }
/*      */       
/*  540 */       int[] tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight), key))), tempLeft);
/*  541 */       for (n = 0; n < 32; n++) {
/*  542 */         ipRight[n] = tempRight[n];
/*      */       }
/*      */     } 
/*      */     
/*  546 */     int[] finalData = new int[64];
/*  547 */     for (i = 0; i < 32; i++) {
/*  548 */       finalData[i] = ipRight[i];
/*  549 */       finalData[32 + i] = ipLeft[i];
/*      */     } 
/*  551 */     return finallyPermute(finalData);
/*      */   }
/*      */   
/*      */   public static int[] initPermute(int[] originalData) {
/*  555 */     int[] ipByte = new int[64];
/*  556 */     int i = 0, m = 1, n = 0;
/*  557 */     for (i = 0, m = 1, n = 0; i < 4; i++, m += 2, n += 2) {
/*  558 */       for (int j = 7, k = 0; j >= 0; j--, k++) {
/*  559 */         ipByte[i * 8 + k] = originalData[j * 8 + m];
/*  560 */         ipByte[i * 8 + k + 32] = originalData[j * 8 + n];
/*      */       } 
/*      */     } 
/*  563 */     return ipByte;
/*      */   }
/*      */   
/*      */   public static int[] expandPermute(int[] rightData) {
/*  567 */     int[] epByte = new int[48];
/*  568 */     int i = 0;
/*  569 */     for (i = 0; i < 8; i++) {
/*  570 */       if (i == 0) {
/*  571 */         epByte[i * 6 + 0] = rightData[31];
/*      */       } else {
/*  573 */         epByte[i * 6 + 0] = rightData[i * 4 - 1];
/*      */       } 
/*  575 */       epByte[i * 6 + 1] = rightData[i * 4 + 0];
/*  576 */       epByte[i * 6 + 2] = rightData[i * 4 + 1];
/*  577 */       epByte[i * 6 + 3] = rightData[i * 4 + 2];
/*  578 */       epByte[i * 6 + 4] = rightData[i * 4 + 3];
/*  579 */       if (i == 7) {
/*  580 */         epByte[i * 6 + 5] = rightData[0];
/*      */       } else {
/*  582 */         epByte[i * 6 + 5] = rightData[i * 4 + 4];
/*      */       } 
/*      */     } 
/*  585 */     return epByte;
/*      */   }
/*      */   
/*      */   public static int[] xor(int[] byteOne, int[] byteTwo) {
/*  589 */     int[] xorByte = new int[byteOne.length];
/*  590 */     for (int i = 0; i < byteOne.length; i++) {
/*  591 */       xorByte[i] = byteOne[i] ^ byteTwo[i];
/*      */     }
/*  593 */     return xorByte;
/*      */   }
/*      */ 
/*      */   
/*      */   public static int[] sBoxPermute(int[] expandByte) {
/*  598 */     int[] sBoxByte = new int[32];
/*  599 */     String binary = "";
/*  600 */     int[][] s1 = { { 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7 }, { 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8 }, { 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0 }, { 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 } };
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */     
/*  606 */     int[][] s2 = { { 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10 }, { 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5 }, { 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15 }, { 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 } };
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */     
/*  612 */     int[][] s3 = { { 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8 }, { 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1 }, { 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7 }, { 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 } };
/*      */ 
/*      */ 
/*      */ 
/*      */     
/*  617 */     int[][] s4 = { { 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15 }, { 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9 }, { 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4 }, { 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 } };
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */     
/*  623 */     int[][] s5 = { { 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9 }, { 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6 }, { 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14 }, { 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 } };
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */     
/*  629 */     int[][] s6 = { { 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11 }, { 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8 }, { 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6 }, { 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 } };
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */     
/*  635 */     int[][] s7 = { { 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1 }, { 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6 }, { 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2 }, { 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 } };
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */     
/*  641 */     int[][] s8 = { { 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7 }, { 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2 }, { 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8 }, { 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 } };
/*      */ 
/*      */ 
/*      */ 
/*      */     
/*  646 */     for (int m = 0; m < 8; m++) {
/*  647 */       int i = 0, j = 0;
/*  648 */       i = expandByte[m * 6 + 0] * 2 + expandByte[m * 6 + 5];
/*  649 */       j = expandByte[m * 6 + 1] * 2 * 2 * 2 + expandByte[m * 6 + 2] * 2 * 2 + expandByte[m * 6 + 3] * 2 + expandByte[m * 6 + 4];
/*      */       
/*  651 */       switch (m) {
/*      */         case 0:
/*  653 */           binary = getBoxBinary(s1[i][j]);
/*      */           break;
/*      */         case 1:
/*  656 */           binary = getBoxBinary(s2[i][j]);
/*      */           break;
/*      */         case 2:
/*  659 */           binary = getBoxBinary(s3[i][j]);
/*      */           break;
/*      */         case 3:
/*  662 */           binary = getBoxBinary(s4[i][j]);
/*      */           break;
/*      */         case 4:
/*  665 */           binary = getBoxBinary(s5[i][j]);
/*      */           break;
/*      */         case 5:
/*  668 */           binary = getBoxBinary(s6[i][j]);
/*      */           break;
/*      */         case 6:
/*  671 */           binary = getBoxBinary(s7[i][j]);
/*      */           break;
/*      */         case 7:
/*  674 */           binary = getBoxBinary(s8[i][j]);
/*      */           break;
/*      */       } 
/*  677 */       sBoxByte[m * 4 + 0] = Integer.parseInt(binary.substring(0, 1));
/*  678 */       sBoxByte[m * 4 + 1] = Integer.parseInt(binary.substring(1, 2));
/*  679 */       sBoxByte[m * 4 + 2] = Integer.parseInt(binary.substring(2, 3));
/*  680 */       sBoxByte[m * 4 + 3] = Integer.parseInt(binary.substring(3, 4));
/*      */     } 
/*  682 */     return sBoxByte;
/*      */   }
/*      */   
/*      */   public static int[] pPermute(int[] sBoxByte) {
/*  686 */     int[] pBoxPermute = new int[32];
/*  687 */     pBoxPermute[0] = sBoxByte[15];
/*  688 */     pBoxPermute[1] = sBoxByte[6];
/*  689 */     pBoxPermute[2] = sBoxByte[19];
/*  690 */     pBoxPermute[3] = sBoxByte[20];
/*  691 */     pBoxPermute[4] = sBoxByte[28];
/*  692 */     pBoxPermute[5] = sBoxByte[11];
/*  693 */     pBoxPermute[6] = sBoxByte[27];
/*  694 */     pBoxPermute[7] = sBoxByte[16];
/*  695 */     pBoxPermute[8] = sBoxByte[0];
/*  696 */     pBoxPermute[9] = sBoxByte[14];
/*  697 */     pBoxPermute[10] = sBoxByte[22];
/*  698 */     pBoxPermute[11] = sBoxByte[25];
/*  699 */     pBoxPermute[12] = sBoxByte[4];
/*  700 */     pBoxPermute[13] = sBoxByte[17];
/*  701 */     pBoxPermute[14] = sBoxByte[30];
/*  702 */     pBoxPermute[15] = sBoxByte[9];
/*  703 */     pBoxPermute[16] = sBoxByte[1];
/*  704 */     pBoxPermute[17] = sBoxByte[7];
/*  705 */     pBoxPermute[18] = sBoxByte[23];
/*  706 */     pBoxPermute[19] = sBoxByte[13];
/*  707 */     pBoxPermute[20] = sBoxByte[31];
/*  708 */     pBoxPermute[21] = sBoxByte[26];
/*  709 */     pBoxPermute[22] = sBoxByte[2];
/*  710 */     pBoxPermute[23] = sBoxByte[8];
/*  711 */     pBoxPermute[24] = sBoxByte[18];
/*  712 */     pBoxPermute[25] = sBoxByte[12];
/*  713 */     pBoxPermute[26] = sBoxByte[29];
/*  714 */     pBoxPermute[27] = sBoxByte[5];
/*  715 */     pBoxPermute[28] = sBoxByte[21];
/*  716 */     pBoxPermute[29] = sBoxByte[10];
/*  717 */     pBoxPermute[30] = sBoxByte[3];
/*  718 */     pBoxPermute[31] = sBoxByte[24];
/*  719 */     return pBoxPermute;
/*      */   }
/*      */   
/*      */   public static int[] finallyPermute(int[] endByte) {
/*  723 */     int[] fpByte = new int[64];
/*  724 */     fpByte[0] = endByte[39];
/*  725 */     fpByte[1] = endByte[7];
/*  726 */     fpByte[2] = endByte[47];
/*  727 */     fpByte[3] = endByte[15];
/*  728 */     fpByte[4] = endByte[55];
/*  729 */     fpByte[5] = endByte[23];
/*  730 */     fpByte[6] = endByte[63];
/*  731 */     fpByte[7] = endByte[31];
/*  732 */     fpByte[8] = endByte[38];
/*  733 */     fpByte[9] = endByte[6];
/*  734 */     fpByte[10] = endByte[46];
/*  735 */     fpByte[11] = endByte[14];
/*  736 */     fpByte[12] = endByte[54];
/*  737 */     fpByte[13] = endByte[22];
/*  738 */     fpByte[14] = endByte[62];
/*  739 */     fpByte[15] = endByte[30];
/*  740 */     fpByte[16] = endByte[37];
/*  741 */     fpByte[17] = endByte[5];
/*  742 */     fpByte[18] = endByte[45];
/*  743 */     fpByte[19] = endByte[13];
/*  744 */     fpByte[20] = endByte[53];
/*  745 */     fpByte[21] = endByte[21];
/*  746 */     fpByte[22] = endByte[61];
/*  747 */     fpByte[23] = endByte[29];
/*  748 */     fpByte[24] = endByte[36];
/*  749 */     fpByte[25] = endByte[4];
/*  750 */     fpByte[26] = endByte[44];
/*  751 */     fpByte[27] = endByte[12];
/*  752 */     fpByte[28] = endByte[52];
/*  753 */     fpByte[29] = endByte[20];
/*  754 */     fpByte[30] = endByte[60];
/*  755 */     fpByte[31] = endByte[28];
/*  756 */     fpByte[32] = endByte[35];
/*  757 */     fpByte[33] = endByte[3];
/*  758 */     fpByte[34] = endByte[43];
/*  759 */     fpByte[35] = endByte[11];
/*  760 */     fpByte[36] = endByte[51];
/*  761 */     fpByte[37] = endByte[19];
/*  762 */     fpByte[38] = endByte[59];
/*  763 */     fpByte[39] = endByte[27];
/*  764 */     fpByte[40] = endByte[34];
/*  765 */     fpByte[41] = endByte[2];
/*  766 */     fpByte[42] = endByte[42];
/*  767 */     fpByte[43] = endByte[10];
/*  768 */     fpByte[44] = endByte[50];
/*  769 */     fpByte[45] = endByte[18];
/*  770 */     fpByte[46] = endByte[58];
/*  771 */     fpByte[47] = endByte[26];
/*  772 */     fpByte[48] = endByte[33];
/*  773 */     fpByte[49] = endByte[1];
/*  774 */     fpByte[50] = endByte[41];
/*  775 */     fpByte[51] = endByte[9];
/*  776 */     fpByte[52] = endByte[49];
/*  777 */     fpByte[53] = endByte[17];
/*  778 */     fpByte[54] = endByte[57];
/*  779 */     fpByte[55] = endByte[25];
/*  780 */     fpByte[56] = endByte[32];
/*  781 */     fpByte[57] = endByte[0];
/*  782 */     fpByte[58] = endByte[40];
/*  783 */     fpByte[59] = endByte[8];
/*  784 */     fpByte[60] = endByte[48];
/*  785 */     fpByte[61] = endByte[16];
/*  786 */     fpByte[62] = endByte[56];
/*  787 */     fpByte[63] = endByte[24];
/*  788 */     return fpByte;
/*      */   }
/*      */   
/*      */   public static String getBoxBinary(int i) {
/*  792 */     String binary = "";
/*  793 */     switch (i) {
/*      */       case 0:
/*  795 */         binary = "0000";
/*      */         break;
/*      */       case 1:
/*  798 */         binary = "0001";
/*      */         break;
/*      */       case 2:
/*  801 */         binary = "0010";
/*      */         break;
/*      */       case 3:
/*  804 */         binary = "0011";
/*      */         break;
/*      */       case 4:
/*  807 */         binary = "0100";
/*      */         break;
/*      */       case 5:
/*  810 */         binary = "0101";
/*      */         break;
/*      */       case 6:
/*  813 */         binary = "0110";
/*      */         break;
/*      */       case 7:
/*  816 */         binary = "0111";
/*      */         break;
/*      */       case 8:
/*  819 */         binary = "1000";
/*      */         break;
/*      */       case 9:
/*  822 */         binary = "1001";
/*      */         break;
/*      */       case 10:
/*  825 */         binary = "1010";
/*      */         break;
/*      */       case 11:
/*  828 */         binary = "1011";
/*      */         break;
/*      */       case 12:
/*  831 */         binary = "1100";
/*      */         break;
/*      */       case 13:
/*  834 */         binary = "1101";
/*      */         break;
/*      */       case 14:
/*  837 */         binary = "1110";
/*      */         break;
/*      */       case 15:
/*  840 */         binary = "1111";
/*      */         break;
/*      */     } 
/*  843 */     return binary;
/*      */   }
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   
/*      */   public static int[][] generateKeys(int[] keyByte) {
/*  851 */     int[][] keys = new int[16][48];
/*  852 */     int[] key = new int[56];
/*  853 */     int[] loop = { 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 };
/*      */     int i;
/*  855 */     for (i = 0; i < 7; i++) {
/*  856 */       for (int j = 0, k = 7; j < 8; j++, k--) {
/*  857 */         key[i * 8 + j] = keyByte[8 * k + i];
/*      */       }
/*      */     } 
/*      */     
/*  861 */     i = 0;
/*  862 */     for (i = 0; i < 16; i++) {
/*  863 */       int tempLeft = 0;
/*  864 */       int tempRight = 0;
/*  865 */       for (int j = 0; j < loop[i]; j++) {
/*  866 */         tempLeft = key[0];
/*  867 */         tempRight = key[28];
/*  868 */         for (int k = 0; k < 27; k++) {
/*  869 */           key[k] = key[k + 1];
/*  870 */           key[28 + k] = key[29 + k];
/*      */         } 
/*  872 */         key[27] = tempLeft;
/*  873 */         key[55] = tempRight;
/*      */       } 
/*  875 */       int[] tempKey = new int[48];
/*  876 */       tempKey[0] = key[13];
/*  877 */       tempKey[1] = key[16];
/*  878 */       tempKey[2] = key[10];
/*  879 */       tempKey[3] = key[23];
/*  880 */       tempKey[4] = key[0];
/*  881 */       tempKey[5] = key[4];
/*  882 */       tempKey[6] = key[2];
/*  883 */       tempKey[7] = key[27];
/*  884 */       tempKey[8] = key[14];
/*  885 */       tempKey[9] = key[5];
/*  886 */       tempKey[10] = key[20];
/*  887 */       tempKey[11] = key[9];
/*  888 */       tempKey[12] = key[22];
/*  889 */       tempKey[13] = key[18];
/*  890 */       tempKey[14] = key[11];
/*  891 */       tempKey[15] = key[3];
/*  892 */       tempKey[16] = key[25];
/*  893 */       tempKey[17] = key[7];
/*  894 */       tempKey[18] = key[15];
/*  895 */       tempKey[19] = key[6];
/*  896 */       tempKey[20] = key[26];
/*  897 */       tempKey[21] = key[19];
/*  898 */       tempKey[22] = key[12];
/*  899 */       tempKey[23] = key[1];
/*  900 */       tempKey[24] = key[40];
/*  901 */       tempKey[25] = key[51];
/*  902 */       tempKey[26] = key[30];
/*  903 */       tempKey[27] = key[36];
/*  904 */       tempKey[28] = key[46];
/*  905 */       tempKey[29] = key[54];
/*  906 */       tempKey[30] = key[29];
/*  907 */       tempKey[31] = key[39];
/*  908 */       tempKey[32] = key[50];
/*  909 */       tempKey[33] = key[44];
/*  910 */       tempKey[34] = key[32];
/*  911 */       tempKey[35] = key[47];
/*  912 */       tempKey[36] = key[43];
/*  913 */       tempKey[37] = key[48];
/*  914 */       tempKey[38] = key[38];
/*  915 */       tempKey[39] = key[55];
/*  916 */       tempKey[40] = key[33];
/*  917 */       tempKey[41] = key[52];
/*  918 */       tempKey[42] = key[45];
/*  919 */       tempKey[43] = key[41];
/*  920 */       tempKey[44] = key[49];
/*  921 */       tempKey[45] = key[35];
/*  922 */       tempKey[46] = key[28];
/*  923 */       tempKey[47] = key[31];
/*  924 */       int m = 0;
/*  925 */       switch (i) {
/*      */         case 0:
/*  927 */           for (m = 0; m < 48; m++) {
/*  928 */             keys[0][m] = tempKey[m];
/*      */           }
/*      */           break;
/*      */         case 1:
/*  932 */           for (m = 0; m < 48; m++) {
/*  933 */             keys[1][m] = tempKey[m];
/*      */           }
/*      */           break;
/*      */         case 2:
/*  937 */           for (m = 0; m < 48; m++) {
/*  938 */             keys[2][m] = tempKey[m];
/*      */           }
/*      */           break;
/*      */         case 3:
/*  942 */           for (m = 0; m < 48; m++) {
/*  943 */             keys[3][m] = tempKey[m];
/*      */           }
/*      */           break;
/*      */         case 4:
/*  947 */           for (m = 0; m < 48; m++) {
/*  948 */             keys[4][m] = tempKey[m];
/*      */           }
/*      */           break;
/*      */         case 5:
/*  952 */           for (m = 0; m < 48; m++) {
/*  953 */             keys[5][m] = tempKey[m];
/*      */           }
/*      */           break;
/*      */         case 6:
/*  957 */           for (m = 0; m < 48; m++) {
/*  958 */             keys[6][m] = tempKey[m];
/*      */           }
/*      */           break;
/*      */         case 7:
/*  962 */           for (m = 0; m < 48; m++) {
/*  963 */             keys[7][m] = tempKey[m];
/*      */           }
/*      */           break;
/*      */         case 8:
/*  967 */           for (m = 0; m < 48; m++) {
/*  968 */             keys[8][m] = tempKey[m];
/*      */           }
/*      */           break;
/*      */         case 9:
/*  972 */           for (m = 0; m < 48; m++) {
/*  973 */             keys[9][m] = tempKey[m];
/*      */           }
/*      */           break;
/*      */         case 10:
/*  977 */           for (m = 0; m < 48; m++) {
/*  978 */             keys[10][m] = tempKey[m];
/*      */           }
/*      */           break;
/*      */         case 11:
/*  982 */           for (m = 0; m < 48; m++) {
/*  983 */             keys[11][m] = tempKey[m];
/*      */           }
/*      */           break;
/*      */         case 12:
/*  987 */           for (m = 0; m < 48; m++) {
/*  988 */             keys[12][m] = tempKey[m];
/*      */           }
/*      */           break;
/*      */         case 13:
/*  992 */           for (m = 0; m < 48; m++) {
/*  993 */             keys[13][m] = tempKey[m];
/*      */           }
/*      */           break;
/*      */         case 14:
/*  997 */           for (m = 0; m < 48; m++) {
/*  998 */             keys[14][m] = tempKey[m];
/*      */           }
/*      */           break;
/*      */         case 15:
/* 1002 */           for (m = 0; m < 48; m++) {
/* 1003 */             keys[15][m] = tempKey[m];
/*      */           }
/*      */           break;
/*      */       } 
/*      */     } 
/* 1008 */     return keys;
/*      */   }
/*      */ }


/* Location:              D:\文件kjt\WEB-INF\lib\egrant-core-2.2.20240205.1659.jar!\com\iris\egran\\utils\Encrypt.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       1.1.3
 */